import 'package:flutter/material.dart';

import 'package:sainbainu/common/values/colors.dart';

class CustomCell extends StatelessWidget {
  final String title;
  final String? value;
  final String? placeholder;
  final bool hideDivider;
  final VoidCallback? onTap;

  const CustomCell({
    super.key,
    required this.title,
    this.value,
    this.placeholder,
    this.hideDivider = false,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    String formatValue = value ?? '';
    Color valueColor = AppColors.active;
    if (formatValue.isEmpty) {
      formatValue = placeholder ?? '';
      valueColor = AppColors.unactive;
    }
    return Column(
      children: [
        ListTile(
          leading: Text(title),
          minLeadingWidth: 70,
          leadingAndTrailingTextStyle: const TextStyle(
            fontSize: 15,
            color: AppColors.active,
          ),
          title: Text(formatValue),
          titleTextStyle: TextStyle(
            fontSize: 15,
            color: valueColor,
          ),
          tileColor: Colors.white,
          trailing: const Icon(Icons.keyboard_arrow_right),
          contentPadding: const EdgeInsets.only(left: 16, right: 10),
          enableFeedback: true,
          onTap: onTap,
        ),
        if (!hideDivider) _buildDivider(),
      ],
    );
  }

  /// 分割线
  Widget _buildDivider() {
    return const Divider(
      height: 0,
      indent: 16,
      endIndent: 16,
      thickness: 0.5,
      color: AppColors.border,
    );
  }
}
